<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生命周期</title>





</head>

<body>
    <div id="app">
        <div>hello</div>
        <button @click="num++">{{num}}</button>
        <button @click="killSelf">killSelf</button>
    </div>


    <!-- 引入vue -->
    <script src=" https://unpkg.com/vue@3/dist/vue.global.js">
    </script>
    <script>
        const { createApp, ref, onBeforeMount, onMounted, onUpdated, onBeforeUpdate, onBeforeUnmount, onUnmounted, getCurrentInstance } = Vue;
        // 创建Vue实例
        const app = createApp({
            setup() {
                const num = ref(10)

                onBeforeMount(() => {
                    console.log('onBeforeMount');

                })
                onMounted(() => {
                    console.log('onMounted');

                })
                onBeforeUpdate(() => {
                    console.log('onBeforeUpdate')
                })
                onUpdated(() => {
                    console.log('onUpdated');

                })
                onBeforeUnmount(() => {
                    console.log('onBeforeUnmount');

                })
                onUnmounted(() => {
                    console.log('onUnmounted');

                })
                // getCurrentInstance方法在setup顶层调用，返回当前组件实例
                const instance = getCurrentInstance()
                const killSelf = () => {

                    instance.appContext.app.unmount()
                }
                return {
                    num,
                    killSelf
                }
            }

        })




        // 挂载到dom
        app.mount('#app')
    </script>
</body>

</html>